<template>
  <div>
    <van-cell>
      <!-- 标题区域插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ artObj.title }}</span>
          <!-- 单图 -->
          <!-- <van-image v-if="artObj.cover.type === 1"
         class="thumb" 
         :src="artObj.cover.images[0]">
          <template v-slot:error>
             图片走丢了
          </template>
        </van-image> -->
          <img v-if="artObj.cover.type === 1" class="thumb" v-lazy="artObj.cover.images[0]" alt="" />
        </div>
        <!-- 多张图片 -->
        <div class="thumb-box" v-if="artObj.cover.type > 1">
          <img v-for="(imgUrl, index) in artObj.cover.images" :key="index" class="thumb" v-lazy="imgUrl" alt="" />
          <!-- <van-image v-for="(imgUrl, index) in artObj.cover.images" 
        :key="index" 
        class="thumb"
         :src="imgUrl">
          <template v-slot:error>
              图片走丢了
          </template>
        </van-image> -->
        </div>
      </template>
      <!-- label区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ artObj.aut_name }}</span>
            <span>{{ artObj.comm_count }}评论</span>
            <span>{{ formatTime(artObj.pubdate) }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="show = true"></van-icon>
        </div>
      </template>
    </van-cell>
    <!-- 反馈面板 -->
    <van-action-sheet v-model="show" :actions="actions" @cancel="cancelFn" @close="closeFn" @select="onSelect" :cancel-text="bottomText" get-container="body" />
  </div>
</template>

<script>
import { timeAgo } from '@/utils/date.js'
import { firstActions, sencondActions } from '@/api/report.js'
export default {
  props: {
    artObj: Object,
    isShow: {
      type: Boolean,
      dafault: true
    }
  },
  data() {
    return {
      show: false, // 反馈面板，显示或者隐藏
      actions: firstActions,
      bottomText: '取消' // 底部按钮默认文字
    }
  },
  methods: {
    formatTime: timeAgo,
    // 反馈面板-"选项"选择事件
    onSelect(action, item) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      if (action.name === '反馈垃圾内容') {
        this.actions = sencondActions
        this.bottomText = '返回'
      } else if (action.name === '不感兴趣') {
        this.$emit('disLikeEV', this.artObj.art_id)
        this.show = false
      } else {
        this.$emit('reportEV', this.artObj.art_id, action.value)
        this.show = false
      }
    },
    // 反馈面板-底部按钮点击事件
    cancelFn() {
      if (this.bottomText === '返回') {
        this.show = true
        this.actions = firstActions
        this.bottomText = '取消'
      }
    },
    // 反馈面板-关闭面板触发事件
    closeFn() {
      this.actions = firstActions
      this.bottomText = '取消'
    }
  }
}
</script>

<style lang="less" scoped>
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
//图片的样式，矩形黄金比例：0.618
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
//三张图片
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
